//
//  ShareView.m
//  WanCaiC8
//
//  Created by tangang on 2018/7/19.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "ShareView.h"
#import "MyVM.h"
#import "ShareHelper.h"
@implementation ShareView

- (instancetype)init{
    if (self=[super init]) {
        self.backgroundColor=[UIColor colorWithWhite:0 alpha:.2];
        
    }
    return self;
}

- (void)onclickCancle{
    [self removeFromSuperview];
}

- (void)show{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.frame=window.bounds;
    [window  addSubview:self];
    UIView *bottomView=[[UIView alloc]init];
    bottomView.backgroundColor=[UIColor whiteColor];
    [self addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.mas_equalTo(@(real_size(250)));
    }];
    
    QXLable *labTitle=[[QXLable alloc]initTitle];
    labTitle.text=@"分享至";
    [bottomView addSubview:labTitle];
    [labTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomView).with.offset(real_size(10));
        make.centerX.equalTo(bottomView);
    }];
    
    UIView *line=[[UIView alloc]init];
    line.backgroundColor=DEFAULTBGCOLOR;
    [bottomView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(bottomView);
        make.top.equalTo(labTitle.mas_bottom).with.offset(real_size(10));
        make.height.mas_equalTo(@1);
    }];
    
    UIButton *btnWechat=[[UIButton alloc]init];
    [btnWechat setTitle:@"微信好友" forState:UIControlStateNormal];
    [btnWechat.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [btnWechat addTarget:self action:@selector(onclickShare:) forControlEvents:UIControlEventTouchUpInside];
    btnWechat.tag=0;
    [btnWechat setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
    [btnWechat verticalTopImageAndTitle:15 andImage:[UIImage imageNamed:@"share_wechat"]];
    [bottomView addSubview:btnWechat];
    [btnWechat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView);
        make.width.equalTo(bottomView).with.multipliedBy(1/3.0);
        make.top.equalTo(line.mas_bottom).with.offset(10);
        make.height.mas_equalTo(@90);
    }];
    
    UIButton *btnCircleFriends=[[UIButton alloc]init];
    [btnCircleFriends setTitle:@"朋友圈" forState:UIControlStateNormal];
    [btnCircleFriends.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [btnCircleFriends setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
    [btnCircleFriends addTarget:self action:@selector(onclickShare:) forControlEvents:UIControlEventTouchUpInside];
    btnCircleFriends.tag=1;
    [btnCircleFriends verticalTopImageAndTitle:15 andImage:[UIImage imageNamed:@"CircleFriends"]];
    [bottomView addSubview:btnCircleFriends];
    [btnCircleFriends mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bottomView);
        make.width.equalTo(bottomView).with.multipliedBy(1/3.0);
        make.centerY.equalTo(btnWechat);
        make.height.mas_equalTo(@90);
    }];
    
    UIButton *btnQQ=[[UIButton alloc]init];
    [btnQQ setTitle:@"QQ好友" forState:UIControlStateNormal];
    [btnQQ.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [btnQQ setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
    [btnQQ addTarget:self action:@selector(onclickShare:) forControlEvents:UIControlEventTouchUpInside];
    btnQQ.tag=2;
    [btnQQ verticalTopImageAndTitle:15 andImage:[UIImage imageNamed:@"share_qq"]];
    [bottomView addSubview:btnQQ];
    [btnQQ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView);
        make.height.mas_equalTo(@90);
        make.width.equalTo(bottomView).with.multipliedBy(1/3.0);
        make.centerY.equalTo(btnWechat);
    }];
    
    UIView *line1=[[UIView alloc]init];
    line1.backgroundColor=DEFAULTBGCOLOR;
    [bottomView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(bottomView);
        make.top.equalTo(btnWechat.mas_bottom).with.offset(10);
        make.height.mas_equalTo(@(real_size(5)));
    }];
    
    UIButton *btnCancle=[[UIButton alloc]init];
    [btnCancle setTitle:@"取消" forState:UIControlStateNormal];
    [btnCancle.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [btnCancle setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
    [btnCancle addTarget:self action:@selector(onclickCancle) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:btnCancle];
    [btnCancle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(bottomView);
        make.top.equalTo(line1.mas_bottom);
    }];
}

- (void)onclickShare:(UIButton *)sender{
    [[MyVM manage] getInvitationRegWithSuccess:^(id returnValue) {
        
        [ShareHelper shareWithInvitationRegister:sender.tag andDict:returnValue];
        
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
    
    
}

@end
